﻿var editors = new Array();

function myFileBrowser(field_name, url, type, win) {
    tinyMCE.activeEditor.windowManager.open({ file: serviceUrl + '?ed=tmc&type=' + type, title: 'File Browser', width: 860, height: 700, resizable: 'yes', inline: 'yes', close_previous: 'no' }, { window: win, input: field_name }); return false;
}

function TinyMCESetupEditor(host, controlId, cleanGuid, skin, advencedStyles) {

    editors[controlId] = new tinymce.Editor(controlId, {
        accessibility_focus: true,
        schema: 'html5',
        browsers: "msie,gecko,safari,opera",
        forced_root_block: 'p',
        convert_urls: false,
        entity_encoding: 'raw',
        dialog_type: "modal",
        language: 'pl',
        extended_valid_elements: "iframe[src|width|height|style|name|title|align|scrolling|frameborder|allowtransparency]",
        directionality: "ltr",
        editor_deselector: "mceNoEditor",
        spellchecker_rpc_url: "/TinyMCEHandler.ashx?rp=spellchecker",
        body_class: 'wysiwygeditor',
        plugins: "media,template,paste,print,searchreplace,fullscreen,emotions,directionality,table,contextmenu,advimage,inlinepopups,spellchecker,wordcount,safari",
        theme: "advanced",
        custom_undo_redo_levels: 10,
        layout_manager: "SimpleLayout",
        theme_advanced_blockformats: "p,address,pre,h1,h2,h3,h4,h5,h6",
        theme_advanced_styles: advencedStyles,
        theme_advanced_source_editor_width: "780",
        theme_advanced_source_editor_height: "700",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_buttons1: "code,separator,selectall,removeformat,cleanup,cut,copy,separator,paste,pastetext,pasteword,separator,print,separator,undo,redo,separator,search,replace",
        theme_advanced_buttons2: "blockquote,bold,italic,underline,strikethrough,separator,sub,sup,separator,bullist,numlist,separator,outdent,indent,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,anchor,image,media,table,hr,emotions,charmap",
        theme_advanced_buttons3: "template,formatselect,styleselect,separator,cleanup,fullscreen,spellchecker",
        theme_advanced_resizing: true,
        template_external_list_url: "/Services/TinyMceTemplates.ashx?cb=" + cleanGuid,
        content_css: "/csshandler.ashx?skin=" + skin + "&amp;s=1&amp;sv=" + cleanGuid,
        emotions_images_url: '/Data/SiteImages/emoticons/tinymce/',
        file_browser_callback: 'myFileBrowser',
        onchange_callback: 'mojoTinyMCEOnChangeHandler'
    }
        );
    editors[controlId].render();
}

function CKEditorSetupEditor(controlId, cleanGuid, skin, configFile, ckeSkin) {
    var editor = CKEDITOR.replace(controlId,
        {
            customConfig: configFile,
            baseHref: '/',
            height: 700,
            skin: ckeSkin,
            language: 'pl',
            contentsCss: '/csshandler.ashx?skin=' + skin + '&sv=' + cleanGuid,
            bodyClass: 'wysiwygeditor',
            filebrowserWindowWidth: 860,
            filebrowserWindowHeight: 700,
            filebrowserBrowseUrl: '/Dialog/FileDialog.aspx?ed=ck&type=file',
            filebrowserImageBrowseUrl: '/Dialog/FileDialog.aspx?ed=ck&type=image',
            filebrowserFlashBrowseUrl: '/Dialog/FileDialog.aspx?ed=ck&type=media',
            toolbar: 'FullWithTemplates'
        });
    var setupEditor = function (editorObj) {
        //        editorObj.config.stylesCombo_stylesSet = 'mojo:/Services/CKeditorStyles.ashx?cb=818f693fce4b43aca50834409a68357f'; 
        editorObj.config.stylesCombo_stylesSet = 'mojo:/Services/CKeditorStyles.ashx?cb=' + cleanGuid;
        editorObj.config.templates = 'mojo';
        //editorObj.config.templates_files = ['/CKeditorTemplates.ashx?cb=751e15b3-db93-4c43-acf4-7a85566ce6a7'];
        editorObj.config.templates_files = ['/Services/CKeditorTemplates.ashx?cb=' + cleanGuid];
        editorObj.config.templates_replaceContent = false;
        editorObj.config.smiley_path = '/Data/SiteImages/emoticons/';
        editorObj.config.extraPlugins = 'onchange';
        editorObj.on('change', function (e) { hookupGoodbyePrompt("You have un-saved changes, are you sure you want to leave this page without saving?"); });
    };
    setupEditor(editor);
}
